﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <input type="hidden" id="goods_id" col="goods_id">
            <div class="select-list">
                <ul>
                    <li>
                        货物颜色名称：<input id="attr_name" col="attr_name" type="text" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="btn-group-sm hidden-xs" id="toolbar">
            <a id="btnAdd" class="btn btn-success" onclick="showSaveForm(true)"><i class="fa fa-plus"></i> 新增</a>
            <a id="btnEdit" class="btn btn-primary disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
            <a id="btnDelete" class="btn btn-danger disabled" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a>
            <a id="btnDelete1" class="btn btn-danger" onclick="tongForm()">同步</a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    var goodsid = ys.request("goodsid");
    $(function () {
        $("#goods_id").val(goodsid);
        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/QixingManage/StoreGoodsAttr/GetPageListJson")';
        $('#gridTable').ysTable({
            url: queryUrl,
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'attr_name', title: '货物颜色' },
                { field: 'attr_values', title: '货物封面',formatter: function (value, row, index) {
                        if (value)
                        {
                            return '<img class="img-circle img-xs" src="' + row.attr_values + '" onclick=showImage("' + row.attr_values + '") />';
                        }
                    }
                },
                { field: 'count', title: '库存' },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" href="#" onclick="WarehouseList(\'' + row.goods_id + '\',\''+row.attr_name+'\')"><i class="fa fa-list-ul"></i>货物管理</a>');
                        return actions.join('');
                    }
                }
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $('#searchDiv').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function WarehouseList(id,name)
    {
         var url = '@Url.Content("~/QixingManage/StoreGoodsProduct/StoreGoodsProductIndex")' + '?goodsid=' + id+'&name='+name;
        createMenuItem(url, " 货物管理");
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function showImage(imageUrl) {
        var html = '<img src="' + imageUrl + '" width="100%" height="100%" class="img-responsive" />';
        ys.openDialogContent({
            content: html,
            width: 'auto',
            height: 'auto',
            closeBtn: true
        });
    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $('#gridTable').bootstrapTable('getSelections');
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }
        }
        ys.openDialog({
            title: id > 0 ? '编辑' : '添加',
            content: '@Url.Content("~/QixingManage/StoreGoodsAttr/StoreGoodsAttrForm")' + '?id=' + id + '&goodsid=' + goodsid,
            width: '768px',
            height: '550px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function deleteForm() {
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm('确认要删除选中的' + selectedRow.length + '条数据吗？', function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/QixingManage/StoreGoodsAttr/DeleteFormJson")' + '?ids=' + ids,
                    type: 'post',
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }

function tongForm()
{
    ys.confirm('确认要同步数据吗？', function () {
                ys.ajax({
                    url: '@Url.Content("~/QixingManage/StoreGoodsAttr/TBFormJson")',
                    type: 'post',
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
}
</script>
